﻿#pragma once

#include "../../Server/Settings.h"
#include "../../Server/MirEnvir/Envir.h"
#include "../../Server/MirDatabase/QuestInfo.h"
#include <string>
#include <vector>
#include <limits>
#include <any>
#include "../../tangible_filesystem.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;

namespace Server
{
    class QuestInfoForm : public System::Windows::Forms::Form
    {
    public:
        std::string QuestListPath = Path::Combine(Settings::ExportPath, "QuestList.txt");

        virtual ~QuestInfoForm()
        {
            delete components;
            delete tabControl1;
            delete tabPage1;
            delete QuestInfoPanel;
            delete QuestIndexTextBox;
            delete label1;
            delete RemoveButton;
            delete AddButton;
            delete PasteMButton;
            delete CopyMButton;
            delete ExportButton;
            delete ImportButton;
            delete ExportSelectedButton;
            delete label11;
            delete OpenQButton;
            delete QFileNameTextBox;
            delete label29;
            delete QGroupTextBox;
            delete QNameTextBox;
            delete label13;
            delete QuestInfoListBox;
            delete label2;
            delete QTypeComboBox;
            delete label7;
            delete RequiredClassComboBox;
            delete RequiredQuestComboBox;
            delete RequiredMinLevelTextBox;
            delete label9;
            delete label8;
            delete label14;
            delete label12;
            delete label10;
            delete QItemTextBox;
            delete QKillTextBox;
            delete QGotoTextBox;
            delete label3;
            delete QFlagTextBox;
            delete RequiredMaxLevelTextBox;
            delete label4;
        }

        Server::MirEnvir::Envir *getEnvir() const;

    private:
        std::vector<QuestInfo*> _selectedQuestInfos;

    public:
        QuestInfoForm();

    private:
        void AddButton_Click(std::any sender, EventArgs *e);
        void RemoveButton_Click(std::any sender, EventArgs *e);

        void UpdateInterface();

        void RefreshQuestList();

        void QuestInfoListBox_SelectedIndexChanged(std::any sender, EventArgs *e);

        void QuestInfoForm_FormClosed(std::any sender, FormClosedEventArgs *e);

        void PasteMButton_Click(std::any sender, EventArgs *e);


        void ExportAllButton_Click(std::any sender, EventArgs *e);

        void ExportSelected_Click(std::any sender, EventArgs *e);

    public:
        void ExportQuests(std::vector<QuestInfo*> &Quests);


    private:
        void ImportButton_Click(std::any sender, EventArgs *e);

        void QNameTextBox_TextChanged(std::any sender, EventArgs *e);

        void QGroupTextBox_TextChanged(std::any sender, EventArgs *e);

        void QTypeComboBox_SelectedIndexChanged(std::any sender, EventArgs *e);

        void QFileNameTextBox_TextChanged(std::any sender, EventArgs *e);

        void QGotoTextBox_TextChanged(std::any sender, EventArgs *e);

        void QKillTextBox_TextChanged(std::any sender, EventArgs *e);

        void QItemTextBox_TextChanged(std::any sender, EventArgs *e);

        void QFlagTextBox_TextChanged(std::any sender, EventArgs *e);


        void RequiredMinLevelTextBox_TextChanged(std::any sender, EventArgs *e);

        void RequiredMaxLevelTextBox_TextChanged(std::any sender, EventArgs *e);

        void RequiredQuestComboBox_SelectedIndexChanged(std::any sender, EventArgs *e);

        void RequiredClassComboBox_SelectedIndexChanged(std::any sender, EventArgs *e);

        void OpenQButton_Click(std::any sender, EventArgs *e);





        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::IContainer *components = nullptr;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected:
        void Dispose(bool disposing) override;

        #pragma region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
    private:
        void InitializeComponent();

        #pragma endregion

        System::Windows::Forms::TabControl *tabControl1;
        System::Windows::Forms::TabPage *tabPage1;
        System::Windows::Forms::Panel *QuestInfoPanel;
        System::Windows::Forms::TextBox *QuestIndexTextBox;
        System::Windows::Forms::Label *label1;
        System::Windows::Forms::Button *RemoveButton;
        System::Windows::Forms::Button *AddButton;
        System::Windows::Forms::Button *PasteMButton;
        System::Windows::Forms::Button *CopyMButton;
        System::Windows::Forms::Button *ExportButton;
        System::Windows::Forms::Button *ImportButton;
        System::Windows::Forms::Button *ExportSelectedButton;
        System::Windows::Forms::Label *label11;
        System::Windows::Forms::Button *OpenQButton;
        System::Windows::Forms::TextBox *QFileNameTextBox;
        System::Windows::Forms::Label *label29;
        System::Windows::Forms::TextBox *QGroupTextBox;
        System::Windows::Forms::TextBox *QNameTextBox;
        System::Windows::Forms::Label *label13;
        System::Windows::Forms::ListBox *QuestInfoListBox;
        System::Windows::Forms::Label *label2;
        System::Windows::Forms::ComboBox *QTypeComboBox;
        System::Windows::Forms::Label *label7;
        System::Windows::Forms::ComboBox *RequiredClassComboBox;
        System::Windows::Forms::ComboBox *RequiredQuestComboBox;
        System::Windows::Forms::TextBox *RequiredMinLevelTextBox;
        System::Windows::Forms::Label *label9;
        System::Windows::Forms::Label *label8;
        System::Windows::Forms::Label *label14;
        System::Windows::Forms::Label *label12;
        System::Windows::Forms::Label *label10;
        System::Windows::Forms::TextBox *QItemTextBox;
        System::Windows::Forms::TextBox *QKillTextBox;
        System::Windows::Forms::TextBox *QGotoTextBox;
        System::Windows::Forms::Label *label3;
        System::Windows::Forms::TextBox *QFlagTextBox;
        System::Windows::Forms::TextBox *RequiredMaxLevelTextBox;
        System::Windows::Forms::Label *label4;
    };
}
